﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DbLinq.Data.Linq;
using Safe_Driving;

using DbLinq.Factory;
using MySql.Data.MySqlClient;


namespace Safe_Driving.TokenUser
{
    class SingletonTokenUser
    {
        //Constante value
        public static string moniteur = "moniteur";
        public static string commercial = "commercial";   
        
        //Création du datacontexe de App_safedriving
        private static AppSafeDriving dc_gen()
        {

            string dbServer = Environment.GetEnvironmentVariable("DbLinqServer") ?? "nodevovmware";

            string connStr = "server=localhost;user=root;database=safe_driving;port=3306;password=";
            return new AppSafeDriving(new MySqlConnection(connStr));
        }

        public static AppSafeDriving dbApp = dc_gen();
        public AppSafeDriving DbApp
        {
            get { return dbApp; }
            set
            {
                if (dbApp != value)
                {
                    dbApp = value;

                }
            }
        }

        //Création du datacontexe de App_safedriving
        private static SafeDriving dc_gen_wordpress()
        {
            string dbServer = Environment.GetEnvironmentVariable("DbLinqServer") ?? "nodevovmware";

            string connStr = "server=localhost;user=root;database=safe_driving;port=3306;password=;";
            return new SafeDriving(new MySqlConnection(connStr));
        }

        public SafeDriving wP_DB = dc_gen_wordpress();
        public SafeDriving WP_DB
        {
            get { return wP_DB; }
            set
            {
                if (wP_DB != value)
                {
                    wP_DB = value;

                }
            }
        }

        #region aide gestion calendrier/main windows

            public MainWindow mw;
            public MainWindow Mw
            {
                get { return mw; }
                set
                {
                    if(mw != value) {
                        mw = value;
                    }
                }
            }

        #endregion


        #region Attributs

        //TabItem actuellement affché dans l'application
            private string current_tab;
            public string Current_tab
            {
                get { return current_tab; }
                set
                {
                    if (current_tab != value)
                    {
                        current_tab = value;
                     
                    }
                }
            }

            //Type d'utilisateur
            private string user_type;
            public string User_type
            {
                get { return user_type; }
                set
                {
                    if (user_type != value)
                    {
                        user_type = value;
                    }
                }
            }

            //Agence de travaille
            private SFAgeNcE agence;
            public SFAgeNcE Agence
            {
                get { return agence; }
                set
                {
                    if (agence != value)
                    {
                        agence = value;
                    }
                }
            }

             //Utilisateur (Commercial) Connecté
            private SFCommercial commercial_connected;
            public SFCommercial Commercial_connected
            {
                get { return commercial_connected; }
                set
                {
                    if (commercial_connected != value)
                    {
                        commercial_connected = value;
                    }
                }
            }

            //Utilisateur (Moniteur) Connecté
            private SFMonItEUR moniteur_connected;
            public SFMonItEUR Moniteur_connected
            {
                get { return moniteur_connected; }
                set
                {
                    if (moniteur_connected != value)
                    {
                        moniteur_connected = value;
                    }
                }
            }

            //CLient sélectionné
            private SFClient client_selected;
            public SFClient Client_selected
            {
                get { return client_selected; }
                set
                {
                    if (client_selected != value)
                    {
                        client_selected = value;
                    }
                }
            }

        #endregion


        #region Code singleton

            private static SingletonTokenUser _theUniqueInstance = null;

            private SingletonTokenUser() { }

            public static SingletonTokenUser GetInstance()
            {
                if (_theUniqueInstance == null)
                    return _theUniqueInstance = new SingletonTokenUser();
                else
                    return _theUniqueInstance;
            }

        #endregion



    }
}
